﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmEvent.
	/// </summary>
	public class frmEvent : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox solieu;
		private System.Windows.Forms.DateTimePicker tu;
		private System.Windows.Forms.DateTimePicker den;
		private System.Windows.Forms.ComboBox computerid;
		private System.Windows.Forms.ComboBox userid;
		private System.Windows.Forms.ComboBox tableid;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button butOK;
		private System.Windows.Forms.Button butCancel;
		private System.Windows.Forms.DataGrid dataGrid2;
		private bool bClear=true;
		private AccessData a;
		private string user,sql,fie,stime;
		private DataSet ds1 = new DataSet();
		private DataSet ds2;
		DataColumn dc;
		private DataTable dt = new DataTable();
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmEvent(AccessData acc)
		{
			//
			// Required for Windows Form Designer support
			//
			a=acc;
			InitializeComponent();
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmEvent));
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.solieu = new System.Windows.Forms.ComboBox();
			this.tu = new System.Windows.Forms.DateTimePicker();
			this.den = new System.Windows.Forms.DateTimePicker();
			this.computerid = new System.Windows.Forms.ComboBox();
			this.userid = new System.Windows.Forms.ComboBox();
			this.tableid = new System.Windows.Forms.ComboBox();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.butOK = new System.Windows.Forms.Button();
			this.butCancel = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(-6, 5);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Số liệu :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(122, 5);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(24, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "Từ :";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(226, 5);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(32, 23);
			this.label3.TabIndex = 4;
			this.label3.Text = "đến :";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(338, 5);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(32, 23);
			this.label4.TabIndex = 6;
			this.label4.Text = "Máy :";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(472, 5);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(72, 23);
			this.label5.TabIndex = 8;
			this.label5.Text = "Người dùng :";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(634, 5);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(64, 23);
			this.label6.TabIndex = 10;
			this.label6.Text = "Nội dung :";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// solieu
			// 
			this.solieu.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.solieu.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.solieu.Items.AddRange(new object[] {
														"Kế toán"});
			this.solieu.Location = new System.Drawing.Point(42, 5);
			this.solieu.Name = "solieu";
			this.solieu.Size = new System.Drawing.Size(80, 21);
			this.solieu.TabIndex = 1;
			this.solieu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.solieu_KeyDown);
			this.solieu.SelectedIndexChanged += new System.EventHandler(this.solieu_SelectedIndexChanged);
			// 
			// tu
			// 
			this.tu.CalendarFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.tu.CustomFormat = "dd/MM/yyyy";
			this.tu.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.tu.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
			this.tu.Location = new System.Drawing.Point(146, 5);
			this.tu.Name = "tu";
			this.tu.Size = new System.Drawing.Size(80, 21);
			this.tu.TabIndex = 3;
			this.tu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.solieu_KeyDown);
			// 
			// den
			// 
			this.den.CalendarFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.den.CustomFormat = "dd/MM/yyyy";
			this.den.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.den.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
			this.den.Location = new System.Drawing.Point(258, 5);
			this.den.Name = "den";
			this.den.Size = new System.Drawing.Size(80, 21);
			this.den.TabIndex = 5;
			this.den.KeyDown += new System.Windows.Forms.KeyEventHandler(this.solieu_KeyDown);
			// 
			// computerid
			// 
			this.computerid.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.computerid.Location = new System.Drawing.Point(370, 5);
			this.computerid.Name = "computerid";
			this.computerid.Size = new System.Drawing.Size(112, 21);
			this.computerid.TabIndex = 7;
			this.computerid.KeyDown += new System.Windows.Forms.KeyEventHandler(this.solieu_KeyDown);
			// 
			// userid
			// 
			this.userid.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.userid.Location = new System.Drawing.Point(544, 5);
			this.userid.Name = "userid";
			this.userid.Size = new System.Drawing.Size(96, 21);
			this.userid.TabIndex = 9;
			this.userid.KeyDown += new System.Windows.Forms.KeyEventHandler(this.solieu_KeyDown);
			// 
			// tableid
			// 
			this.tableid.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.tableid.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.tableid.Location = new System.Drawing.Point(698, 5);
			this.tableid.Name = "tableid";
			this.tableid.Size = new System.Drawing.Size(86, 21);
			this.tableid.TabIndex = 11;
			this.tableid.KeyDown += new System.Windows.Forms.KeyEventHandler(this.solieu_KeyDown);
			// 
			// dataGrid1
			// 
			this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
			this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.FlatMode = true;
			this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid1.Location = new System.Drawing.Point(8, 10);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.RowHeaderWidth = 10;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.Size = new System.Drawing.Size(776, 330);
			this.dataGrid1.TabIndex = 14;
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			// 
			// butOK
			// 
			this.butOK.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butOK.Image = ((System.Drawing.Bitmap)(resources.GetObject("butOK.Image")));
			this.butOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butOK.Location = new System.Drawing.Point(325, 496);
			this.butOK.Name = "butOK";
			this.butOK.Size = new System.Drawing.Size(70, 25);
			this.butOK.TabIndex = 12;
			this.butOK.Text = "     &Xem";
			this.butOK.Click += new System.EventHandler(this.butOk_Click);
			// 
			// butCancel
			// 
			this.butCancel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butCancel.Image = ((System.Drawing.Bitmap)(resources.GetObject("butCancel.Image")));
			this.butCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butCancel.Location = new System.Drawing.Point(398, 496);
			this.butCancel.Name = "butCancel";
			this.butCancel.Size = new System.Drawing.Size(70, 25);
			this.butCancel.TabIndex = 13;
			this.butCancel.Text = "&Kết thúc";
			this.butCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butCancel.Click += new System.EventHandler(this.butCancel_Click);
			// 
			// frmEvent
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.butCancel,
																		  this.butOK,
																		  this.tableid,
																		  this.userid,
																		  this.computerid,
																		  this.den,
																		  this.tu,
																		  this.solieu,
																		  this.label6,
																		  this.label5,
																		  this.label4,
																		  this.label3,
																		  this.label2,
																		  this.label1,
																		  this.dataGrid1});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmEvent";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Nhật ký người dùng";
			this.Load += new System.EventHandler(this.frmEvent_Load);
			this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmEvent_MouseMove);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmEvent_Load(object sender, System.EventArgs e)
		{
			user = a.user;stime="'dd/mm/yy'";
			dt = a.get_data("select * from " + user + ".a_dmtables").Tables[0];
			a.execute_data("update dmcomputer set id=rownum");
			computerid.DataSource = a.get_data("select * from dmcomputer order by id").Tables[0];
			computerid.DisplayMember = "COMPUTER";
			computerid.ValueMember = "ID";

			sql = "select id,hoten from a_dlogin order by hoten";
			userid.DataSource = a.get_data(sql).Tables[0];
			userid.DisplayMember = "HOTEN";
			userid.ValueMember = "ID";

			tableid.DataSource = a.get_data("select id,nvl(diengiai,tables) as tables from a_dmtables where substr(tables,1,2)='a_' order by id").Tables[0];
			tableid.DisplayMember = "TABLES";
			tableid.ValueMember = "ID";
			ds1.ReadXml("..\\..\\..\\xml\\event.xml");
			dataGrid1.DataSource = ds1.Tables[0];
			AddGridTableStyle();
			solieu.SelectedIndex=0;
		}

		private void solieu_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");
		}

		private void solieu_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==solieu)
			{
				string table="a_dlogin";
				sql = "select id,hoten from "+table+" order by hoten";
				userid.DataSource = a.get_data(sql).Tables[0];
				userid.SelectedIndex=-1;
			}
		}

		private void frmEvent_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (bClear)
			{
				userid.SelectedIndex=-1;
				tableid.SelectedIndex=-1;
				computerid.SelectedIndex=-1;
				bClear=false;
			}
		}

		private void load_grid()
		{
			DataSet tmp;
			string table="a_dlogin";
			sql = "select to_char(a.ngay,'dd/mm/yyyy') as ngay,b.computer as may,c.hoten as tenuser,nvl(d.diengiai,d.tables) as noidung,";
			sql += " a.ins,a.upd,a.del,a.tableid,a.computerid,a.userid ";
			sql+=" from a_eve_tables a,dmcomputer b," + table+" c,a_dmtables d ";
			sql+=" where a.computerid=b.id and a.userid=c.id and a.tableid=d.id ";
			sql+=" and to_date(a.ngay,"+stime+") between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")";
			sql+=" and substr(d.tables,1,2)='a_'";
			if (computerid.SelectedIndex != -1) sql += " and a.computerid=" + int.Parse(computerid.SelectedValue.ToString());
			if (userid.SelectedIndex != -1) sql += " and a.userid=" + int.Parse(userid.SelectedValue.ToString());
			if (tableid.SelectedIndex != -1) sql += " and a.tableid=" + int.Parse(tableid.SelectedValue.ToString());
			tmp = a.get_data(sql);
			ds1.Clear();
			ds1.Merge(tmp.Tables[0].Select("true", "ngay"));
			dataGrid1.DataSource = ds1.Tables[0];
		}

		private void AddGridTableStyle()
		{
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds1.Tables[0].TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly = false;
			ts.RowHeaderWidth = 10;

			DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "ngay";
			TextCol.HeaderText = "Ngày";
			TextCol.Width = 70;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "may";
			TextCol.HeaderText = "Tên máy";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "tenuser";
			TextCol.HeaderText = "Người dùng";
			TextCol.Width = 200;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "noidung";
			TextCol.HeaderText = "Nội dung";
			TextCol.Width = 220;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "ins";
			TextCol.HeaderText = "Thêm";
			TextCol.Width = 50;
			TextCol.Format = "### ### ##0";
			TextCol.Alignment = HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "upd";
			TextCol.HeaderText = "Thay đổi";
			TextCol.Width = 50;
			TextCol.Format = "### ### ##0";
			TextCol.Alignment = HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "del";
			TextCol.HeaderText = "Hủy";
			TextCol.Width = 50;
			TextCol.Format = "### ### ##0";
			TextCol.Alignment = HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "tableid";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "computerid";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "userid";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);
		}

		private void AddGridTableStyle1()
		{
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds2.Tables[0].TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly = false;
			ts.RowHeaderWidth = 10;

			DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "ngayevent";
			TextCol.HeaderText = "Ngày";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			TextCol = new DataGridTextBoxColumn();
			TextCol.MappingName = "command";
			TextCol.HeaderText = "Thao tác";
			TextCol.Width = 60;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid2.TableStyles.Add(ts);

			if (fie == "")
			{
				TextCol = new DataGridTextBoxColumn();
				TextCol.MappingName = "noidung";
				TextCol.HeaderText = "Nội dung";
				TextCol.Width = 582;
				ts.GridColumnStyles.Add(TextCol);
				dataGrid2.TableStyles.Add(ts);
			}
			else
			{
				string ten = "";
				for (int i = 3; i < ds2.Tables[0].Columns.Count; i++)
				{
					ten = ds2.Tables[0].Columns[i].ColumnName;
					TextCol = new DataGridTextBoxColumn();
					TextCol.MappingName = ten;
					TextCol.HeaderText = ten;
					TextCol.Width = (ten.IndexOf("chandoan") != -1) ? 200 : 80;
					ts.GridColumnStyles.Add(TextCol);
					dataGrid2.TableStyles.Add(ts);
				}
			}
		}

		private void butOk_Click(object sender, EventArgs e)
		{
			load_grid();
		}

		private void butCancel_Click(object sender, EventArgs e)
		{
			a.close();System.GC.Collect();this.Close();
		}

		private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
		{
			ref_text();
		}
		private void ref_text()
		{
			string ngay = tu.Text;
			int itable = 0, icomputer = 0, iuser = 0;
			try
			{
				int i = dataGrid1.CurrentCell.RowNumber;
				ngay = dataGrid1[i, 0].ToString();
				itable = int.Parse(dataGrid1[i, 7].ToString());
				icomputer = int.Parse(dataGrid1[i, 8].ToString());
				iuser = int.Parse(dataGrid1[i, 9].ToString());                
			}
			catch { }
			load_data(ngay, itable, icomputer, iuser);
		}

		private void load_data(string ngay, int itable, int icomputer, int iuser)
		{
			try
			{
				DataSet tmp;
				int i = dataGrid1.CurrentCell.RowNumber;
				sql = "select to_char(ngay,'yymmddhh24mi') as yymmdd,to_char(ngay,'dd/mm/yyyy hh24:mi') as ngayevent,case when command='upd' then 'Thay doi' else 'Huy' end as command,noidung ";
				sql += " from " + user + ".a_eve_upd_del a,"+user+".a_dmtables b where a.tableid=b.id and substr(b.tables,1,2)='a_' and to_char(a.ngay,'dd/mm/yyyy')='" + ngay + "' and a.tableid=" + itable + " and a.computerid=" + icomputer + " and a.userid=" + iuser;
				tmp = a.get_data(sql);
				//
				ds2 = new DataSet();
				ds2.ReadXml("..\\..\\..\\xml\\event_upd_del.xml");
				DataRow r1 = a.getrowbyid(dt, "id=" + itable);
				if (r1 != null) fie = r1["fields"].ToString().Trim();
				else fie = "";
				if (fie != "")
				{
					ds2.Tables[0].Columns.Remove("noidung");
					int j = 0, len = fie.Length, k = 0;
					string s = "", s1 = "";
					while (j < len)
					{
						if (fie.Substring(j, 1) == "^")
						{
							dc = new DataColumn();
							dc.ColumnName = s;
							dc.DataType = Type.GetType("System.String");
							ds2.Tables[0].Columns.Add(dc);
							s = "";
						}
						else s += fie.Substring(j, 1);
						j++;
					}
					if (s != "")
					{
						dc = new DataColumn();
						dc.ColumnName = s;
						dc.DataType = Type.GetType("System.String");
						ds2.Tables[0].Columns.Add(dc);
					}
					foreach (DataRow r in tmp.Tables[0].Rows)
					{
						r1 = ds2.Tables[0].NewRow();
						r1["ngayevent"] = r["ngayevent"].ToString();
						r1["command"] = r["command"].ToString();
						k = 3; j = 0; s = ""; s1 = r["noidung"].ToString().Trim(); len = s1.Length;
						while (j < len)
						{
							if (s1.Substring(j, 1) == "^")
							{
								r1[k] = s;
								k++; s = "";
							}
							else s += s1.Substring(j, 1);
							j++;
						}
						if (s != "") r1[k] = s;
						ds2.Tables[0].Rows.Add(r1);
					}
				}
				else ds2.Merge(tmp.Tables[0].Select("true", "command,yymmdd"));
				foreach (System.Windows.Forms.Control c in this.Controls) if (c.Name == "dataGrid2") this.Controls.Remove(c);
				dataGrid2 = new System.Windows.Forms.DataGrid();
				dataGrid2.AlternatingBackColor = System.Drawing.Color.Lavender;
				this.dataGrid2.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
					| System.Windows.Forms.AnchorStyles.Left) 
					| System.Windows.Forms.AnchorStyles.Right);
				dataGrid2.BackColor = System.Drawing.Color.WhiteSmoke;
				dataGrid2.BackgroundColor = System.Drawing.SystemColors.Control;
				dataGrid2.BorderStyle = System.Windows.Forms.BorderStyle.None;
				dataGrid2.CaptionBackColor = System.Drawing.SystemColors.Control;
				dataGrid2.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
				dataGrid2.CaptionForeColor = System.Drawing.Color.Red;
				dataGrid2.DataMember = "";
				dataGrid2.FlatMode = true;
				dataGrid2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
				dataGrid2.ForeColor = System.Drawing.Color.MidnightBlue;
				dataGrid2.GridLineColor = System.Drawing.Color.Gainsboro;
				dataGrid2.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
				dataGrid2.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
				dataGrid2.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
				dataGrid2.LinkColor = System.Drawing.Color.Teal;
				dataGrid2.Location = new System.Drawing.Point(8, 342);
				dataGrid2.Name = "dataGrid2";
				dataGrid2.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
				dataGrid2.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
				dataGrid2.ReadOnly = true;
				dataGrid2.RowHeaderWidth = 10;
				dataGrid2.SelectionBackColor = System.Drawing.Color.CadetBlue;
				dataGrid2.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
				dataGrid2.Size = new System.Drawing.Size(776, 145);
				dataGrid2.TabIndex = 10;
				dataGrid2.CaptionText = ngay + "; " + dataGrid1[i, 1].ToString().Trim() + "; " + dataGrid1[i, 2].ToString().Trim() + "; " + dataGrid1[i, 3].ToString().Trim();
				dataGrid2.DataSource = ds2.Tables[0];
				AddGridTableStyle1();
				this.Controls.Add(dataGrid2);
			}
			catch { }
		}

	}
}
